home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- import time
- import socket
- import subprocess
- gmail_ips = ('66.249.93.111', '66.249.93.109', '64.233.183.109', '72.14.205.109', '66.249.83.109', '66.249.83.111', '64.233.185.109', '64.233.185.111')
- at_home_ips = ('213.51.130.46', '213.51.146.46')
- telenet_ips = ('195.130.137.66', '195.130.132.42', '195.130.132.37', '195.130.137.65')
- yahoo_ips = ('66.163.171.139', '68.142.229.13')
- bellsouth_ips = ('205.152.59.16', '205.152.59.17')
- wanadoo_ips = ('193.252.22.231', '193.252.22.232')
- comcast_ips = ('204.127.198.10', '204.127.202.10', '63.240.76.10', '216.148.227.80')
- t_online_ips = ('194.25.134.47', '194.25.134.111')
-
- class DNSLookup(object):
- ONE_HOUR = 60 * 60
- ONE_WEEK = ONE_HOUR * 24 * 7
-
- def __init__(self):
- self.reset_cache()
- self.generation_time = time.time() - self.ONE_HOUR
-
-
- def reset_cache(self):
- self.cache = { }
- self.live_times = { }
-
-
- def generate_cache(self):
- p = subprocess.Popen('ipconfig /displaydns', stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr = subprocess.STDOUT, shell = True).stdout
- for line in p.readlines():
- line = line.strip()
- if line and not line.strip('-'):
- host = previous
-
- if line.startswith('A (Host) Record'):
- self.cache[line.split(':')[1].strip()] = host
-
- if line.startswith('Time To Live'):
- self.live_times[host] = float(line.split(':')[1])
-
- previous = line
-
- for ip_list, cname in ((gmail_ips, 'pop.gmail.com'), (at_home_ips, 'mail.home.nl'), (telenet_ips, 'telenet-ops.be'), (yahoo_ips, 'mail.yahoo.com'), (bellsouth_ips, 'mail.bellsouth.net'), (comcast_ips, 'pop.comcast.net')):
- for ip in ip_list:
- if ip not in self.cache:
- self.cache[ip] = cname
- continue
- else:
- self.live_times[cname] = time.time() + self.ONE_WEEK
-
- self.generation_time = time.time()
-
-
- def get_host(self, ip):
-
- try:
- host = self.cache[ip]
- if time.time() > self.live_times[host] + self.generation_time:
- host = None
- except KeyError:
- host = None
-
- if host:
- return host
-
- if time.time() > self.generation_time + self.ONE_HOUR:
- self.generate_cache()
- return self.get_host(ip)
-
- old_timeout = socket.getdefaulttimeout()
- socket.setdefaulttimeout(5)
-
- try:
- host = socket.gethostbyaddr(ip)[0]
- except socket.error:
- host = ip
-
- socket.setdefaulttimeout(old_timeout)
- self.cache[ip] = host
- self.live_times[host] = time.time() + self.ONE_HOUR
- return host
-
-
- def __getitem__(self, ip):
- return self.get_host(ip)
-
-
- lookup = DNSLookup()
-